#pragma once

#include "D3DUtils.h"
#include "Component.h"

class D3DApp
{
public:
	D3DApp();
	D3DApp(HINSTANCE hInstance, std::string winCaption
		, D3DDEVTYPE devType, DWORD requestedVP);
	virtual ~D3DApp();

	D3DPRESENT_PARAMETERS GetD3DPP() { return mD3Dpp; }
	HWND GetMainWindow() { return mhMainWindow; }
	HINSTANCE GetAppInstance() { return mhAppInstance; }
	bool GetDeviceLost();
	
	D3DXVECTOR3 GetCameraPosition(){ return pos; }
	void SetCameraPosition(D3DXVECTOR3 _pos){ pos = _pos; }
	void SetCameraPosition(float x, float y, float z){ pos.x = x; pos.y = y; pos.z = z; }

	virtual LRESULT MsgProc(UINT msg, WPARAM wParam, LPARAM lParam);
	virtual int Run();

protected:
	virtual void InitMainWindow();
	virtual void InitDirect3D();

	virtual bool CheckDeviceCaps()	{ return true; }
	virtual void OnLostDevice();
	virtual void OnResetDevice();
	virtual void Update(double dt);
	virtual void Draw(ID3DXSprite& sprite, D3DXMATRIX& view, D3DXMATRIX& proj);

	void EnableFullscreen();

	HWND mhMainWindow;
	HINSTANCE mhAppInstance;
	std::string mMainWindowCaption;

	IDirect3D9* mD3DObject;
	ID3DXSprite* mSprite;

	D3DPRESENT_PARAMETERS mD3Dpp;
	D3DDEVTYPE mDevType;
	DWORD mRequestedVP;

	D3DXMATRIX mView;
	D3DXMATRIX mProj;
	D3DXVECTOR3 pos;
	D3DXVECTOR3 up;
	D3DXVECTOR3 target;

	bool mAppPaused;

private:
	void BuildViewProjMtx();

	void ResetDevice();
};


